﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ciloci.Flee;
using System.IO;

namespace fleeEval
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Delta Compiler Version 1.0";
            StreamReader input = null;

            //list positions
            int iter = 0;
            int WhileStart = 0;
            bool whileLoopFlag = false;

            try
            {
                input = new StreamReader(args[0]);
            }
            catch
            {
                Console.WriteLine("error opening source file: " + args[1]);
                Environment.Exit(1);
            }

            //list of lines
            List<string> list = new List<string>();
            while (!input.EndOfStream)
            {
                list.Add(input.ReadLine());
            }

            parser parser = new parser(ref list, ref iter, ref WhileStart);

            //main loop
            while (iter < list.Count)
            {
                if (whileLoopFlag == true)
                {
                    iter = WhileStart;
                }
                parser.fetchLine(list[iter], ref iter, ref WhileStart);
                if (parser.checkInput(out iter))
                {
                    if (!parser.checkEval())
                    {
                        if (parser.checkSyntax())
                        {
                            parser.splitString();
                            parser.eval(out iter, out WhileStart);
                            iter++;
                        }
                    }
                    else
                    {
                        iter++;
                    }
                }
            }
            Console.ReadKey();
        }
    }
}
